import axios from '@/api/interceptor';
import { LocaleData } from '@/api/locale/types';

export const selectPageLocale = async (params: any) => {
  const result = await axios({
    url: '/locale/listPage',
    method: 'GET',
    params,
  });
  return result.data;
};

export const list = async (locale: string) => {
  const result = await axios({
    url: '/locale/list',
    method: 'GET',
    params: { locale },
  });
  return result.data;
};

export const createLocale = async (locale: LocaleData) => {
  const result = await axios({
    url: '/locale/createLocale',
    method: 'POST',
    data: locale,
  });
  return result.data;
};

export const editLocale = async (locale: LocaleData) => {
  const result = await axios({
    url: '/locale/editLocale',
    method: 'PUT',
    data: locale,
  });
  return result.data;
};

export const selectKeyList = async (key: string) => {
  const result = await axios({
    url: '/locale/key',
    method: 'GET',
    params: { key },
  });
  return result.data;
};

export const detail = async (key: string) => {
  const result = await axios({
    url: '/locale/detail',
    method: 'GET',
    params: { key },
  });
  return result.data;
};

export const removeByKey = async (key: string) => {
  const result = await axios({
    url: '/locale/removeLocal',
    method: 'DELETE',
    params: { key },
  });
  return result.data;
};
